public class Sorter {
    public void traversal( int[] array ){    
        if( array != null && array.length > 0 ) {       
             for( int i = 0 ; i < array.length ; i++ ){          
                    System.out.print( array[ i ] );          
                    System.out.print( ( i < array.length - 1 ) ? " , " : "" );      
                }        
                System.out.println();   
        }
     }

     public int[] sort( int[] array ) {    
         int[] a=new int[array.length];
         System.arraycopy(array, 0, a, 0, array.length);
         for(int i=0;i<a.length-1;i++){
            for(int j=0;j<a.length-1-i;j++){
                if(a[j]>a[j+1]){
                   a[j]^=a[j+1];
                   a[j+1]^=a[j];
                   a[j]^=a[j+1];
                }
            }
        }
        return a;
         // 实现排序并返回新数组
        }

    public static void main(String[] args) {
        Sorter sorter = new Sorter();
        int[] a = { 1 , 100 , -20 , 99 , 1000 , 0 , 30 }; 
        
        System.out.print( "ܻ原数组: " ); 
        sorter.traversal( a ); // ܻ原数组: 1 , 100 , -20 , 99 , 1000 , 0 , 30
        
        int[] x = sorter.sort( a ) ;
        System.out.print( "新数组: " );
        sorter.traversal( x ); //新数组: -20 , 0 , 1 , 30 , 99 , 100 , 1000
        
        System.out.print( "原数组: " ); 
        sorter.traversal( a ); //原数组: 1 , 100 , -20 , 99 , 1000 , 0 , 30
    }
}